// import store from './store'
import { router } from '~/router'
import { getStorage, removeStorage, setStorage } from '~/composables/storage'
import { useUserStore } from './store/user'
import {
  hideFullLoading,
  showFullLoading,
} from '~/composables/util'

const AuthUrls = ['/my', '/organization', '/liveRoom']
// 全局前置守卫
let hasGetInfo = false
router.beforeEach(async (to, from, next) => {
  // 显示loading
  showFullLoading()

  //   store.commit('SET_BOTTOM', to.meta.isBottom)

  // 设置页面标题
  const title = `${to.meta.title ? to.meta.title : ''}-${import.meta.env.VITE_APP_BASE_TITLE}`
  document.title = title

  const userStore = useUserStore()
  const token = userStore.token
  console.log(token, 'token')
  if (token && !hasGetInfo) {
    // store.dispatch('getinfo')
    hasGetInfo = true
  }


  if (to.meta.isLogin) {
    if (token)
      next()

    else
      next('/login')
  }
  else {
    next()
  }
})

// 全局后置守卫
router.afterEach((to, from) => hideFullLoading())
